package com.example.mr5.money.util;/**
 * Created by Mr.5
 * Date：2016/9/18.
 * Time：21:22
 */

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Mr.5
 * Date：2016/9/18.
 * Time：21:22
 */
public class DateUtil {

    public DateUtil() {
    }

    public static String fmtDateToStr(Date date, String dtFormat) {
        if (date == null) {
            return "";
        } else {
            try {
                SimpleDateFormat e = new SimpleDateFormat(dtFormat);
                return e.format(date);
            } catch (Exception var3) {
                var3.printStackTrace();
                return "";
            }
        }
    }

    public static Date fmtStr2Date(String dateStr, String dtFormat) {
        if (dateStr == null) {
            return null;
        } else {
            try {
                SimpleDateFormat e = new SimpleDateFormat(dtFormat);
                return e.parse(dateStr);
            } catch (Exception var3) {
                var3.printStackTrace();
                return null;
            }
        }
    }

    public static String getMonthFromDate(String date){
        String[] s = date.split("-");
        return s[1];
    }

    public static String getYearFromDate(String date){
        String[] s = date.split("-");
        return s[0];
    }
}
